package com.example.my_objectives;

import java.util.ArrayList;

import android.app.Activity;
import android.content.ContentValues;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ProgressBar;
import android.widget.TextView;


public class ObjectiveList extends ArrayAdapter<String> {
	private Activity _context;
	private String[] _name;
	private String[] _description;
	private Integer[] _value;


	public ObjectiveList(Activity context, ArrayList<ContentValues> data) {
		super(context, R.layout.list_item);
		_context = context;
		int i = 0;
		for (ContentValues contentValues : data) {
			_name[i] = contentValues.getAsString("name");
			_description[i] = contentValues.getAsString("description");
			_value[i] = contentValues.getAsInteger("total_values");
		}//for each
	}

	@Override
	public View getView(int position, View view, ViewGroup parent) {
		LayoutInflater inflater = _context.getLayoutInflater();
		View rowView = inflater.inflate(R.layout.list_item, null, true);
		TextView tvName = (TextView) rowView.findViewById(R.id.tvObjectiveName);
		TextView tvPercentage = (TextView) rowView.findViewById(R.id.tvObjectivePercentage);
		TextView tvDescription = (TextView) rowView.findViewById(R.id.tvObjectiveDescription);
		ProgressBar pbProgress = (ProgressBar) rowView.findViewById(R.id.pbObjectiveProgress);

		tvName.setText(_name[position]);
		tvPercentage.setText(_value[position].toString() + "%");
		tvDescription.setText(_description[position]);
		pbProgress.setProgress(_value[position]);

		return rowView;
	}

}
